#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct Item {
    int id;
    int value;
    int weight;
};

void backtrack(const vector<Item>& items, int capacity, 
              int current_value, int& max_value, 
              int remaining_weight, int index) {
    // 基本情况：已经考虑完所有物品
    if (index == items.size()) {
        if (current_value > max_value && remaining_weight >= 0) {
            max_value = current_value;
        }
        return;
    }
    
    // 剪枝：如果剩余容量还能装下当前物品，才考虑选择它
    if (items[index].weight <= remaining_weight) {
        // 选择当前物品
        backtrack(items, capacity, 
                 current_value + items[index].value, max_value,
                 remaining_weight - items[index].weight, 
                 index + 1);
    }
    
    // 不选择当前物品
    backtrack(items, capacity, 
             current_value, max_value,
             remaining_weight, 
             index + 1);
}

int main(int argc, char* argv[]) {
    // 检查是否提供了文件路径参数
    if (argc < 2) {
        cerr << "Usage: " << argv[0] << " <filepath>" << endl;
        return 1;
    }
    
    string filepath = argv[1];  // 获取文件路径参数

    int n, id, value, weight, capacity;
    cin >> n;

    vector<Item> items(n);
    for (int i = 0; i < n; ++i) {
        cin >> id >> value >> weight;
        cout << "cin" << endl;
        items[i] = {id, value, weight};
    }

    cin >> capacity;

    int max_value = -1; // 初始化为-1表示无解
    backtrack(items, capacity, 0, max_value, capacity, 0);

    // 输出结果：filepath,total_value
    cout << filepath << "," << max_value << endl;

    return 0;
}